package com.bawei.mall.product.service.impl;

import com.bawei.mall.product.domain.MallProductHotWord;
import com.bawei.mall.product.mapper.MallProductHotWordMapper;
import com.bawei.mall.product.service.IMallProductHotWordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName MallProductHostWord
 * @Description 描述
 * @Author ZiZheng.Li
 * @Date 2024/6/26 9:21
 */
@Service
public class MallProductHotWordServiceImpl implements IMallProductHotWordService {
    @Autowired
    private MallProductHotWordMapper mallProductHotWordMapper;

    @Override
    @Transactional
    public void insertMallProductHotWord(MallProductHotWord mallProductHotWord) {
        //查询数据库是否已经存在该热词
        MallProductHotWord productHotWord=mallProductHotWordMapper.selectMallProductHotWordByKeyWord(mallProductHotWord.getKeyWord());
        if (productHotWord!=null){
            mallProductHotWordMapper.updateMallProductHotWord(productHotWord);
        }
        mallProductHotWordMapper.insertMallProductHotWord(mallProductHotWord);
    }

    @Override
    public List<MallProductHotWord> selectMallProductHotWordList() {
        List<MallProductHotWord> hotWords=mallProductHotWordMapper.selectMallProductHotWordList();
        return hotWords;
    }
}
